home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 15 / BBS in a box XV-2.iso / Files II / Prog / N-P / OOP for C.sit / OIC.ƒ / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-09  |  3.8 KB  |  177 lines  |  [TEXT/KAHL]

  1. /*
  2.  *        Objects-In-C test program
  3.  *
  4.  *            Copyright © John Wainwright 1988
  5.  *
  6.  */
  7.  
  8. #include <stdio.h>
  9. #include "oic.h"
  10. #include "generics.h"
  11.  
  12. enum { TITLE = 1, BOUNDS, KIND };        
  13. extern class         Window;                
  14.  
  15. main()
  16. {
  17.     object            p1, p2;
  18.     object            box1, box2;
  19.     object            list1, list2;
  20.     object            seq, item;
  21.     register int    i;
  22.     register long    time;
  23.     extern  class      Coord, Box, Window;
  24.     object            d, w;
  25.     static Rect     bounds = {100, 100, 350, 350};
  26.  
  27.     MaxApplZone();
  28.     InitOIC();
  29.     InitSysClasses();
  30.     InitTestClasses();
  31.  
  32. /*
  33.     TraceClass(List);
  34.     TraceOn();
  35. */
  36.     
  37.     /*
  38.      *  play with strings & lists
  39.      */
  40.      
  41.     print(New(String, "hello world"));
  42.     list1 = New(List,
  43.                New(String, "one"),
  44.                New(String, "two"),
  45.                New(String, "three"), END);
  46.     print(list1);
  47.     print(head(list1));
  48.     print(tail(list1));
  49.     print(list1);
  50.     print(add(list1, New(String, "four"),
  51.             New(List,
  52.                New(String, "one"),
  53.                New(String, "two"),
  54.                New(String, "three"), END), END));
  55.     
  56.     /* 
  57.      * Coords & Boxes
  58.      */
  59.      
  60.     print((p1 = New(Coord, 100.0, 100.0)));
  61.     offset(p1, 2.0, 4.0);
  62.     print(p1);
  63.     p2 = New(Coord, 200.0, 200.0);
  64.     print((box1 = New(Box, 100.0, 100.0, 200.0, 200.0)));
  65.     
  66.     /*
  67.      *  add different things to the original list
  68.      */
  69.     add(list1, p1, box1, New(List, box1, p1, END), END);
  70.     print(list1);
  71.     print(push(list1, p1));
  72.     printf("%s %s\n", ClassNameOf(list1), ClassNameOf(p1));
  73.  
  74.     /*
  75.      * experiment with the sequencing classes
  76.      */
  77.      
  78.     for (seq = sequence(list1); item = next(seq);)
  79.         print(item);
  80.     
  81.     /*
  82.      * or, more simply, using the "map" generic 
  83.      */
  84.      
  85.     map(list1, print);
  86.     
  87.     /*
  88.      *  Coords inherit from indexMixin which keeps track of
  89.      *  all instances - it provides a class method for "sequence"
  90.      *    to allow us to simply sequence over all instances
  91.      *  see how neat it all is ?
  92.      */
  93.     printf("\nall Coord instances...\n");
  94.     for (seq = sequence(Coord); item = next(seq);)
  95.     {
  96.         printf("-> "); print(item);
  97.     }
  98.  
  99.     /*
  100.      * indexMixin can find ALL its kept instances ...
  101.      */
  102.     printf("\nall indexMixin deepinstances...\n");
  103.     for (seq = sequence(deepInstances(IndexMixin)); item = next(seq);)
  104.     {
  105.         printf("-> "); print(New(List, item, className(item), END));
  106.     }
  107.  
  108.     /*
  109.      * playing with other kind of list
  110.      */
  111.     printf("\ntrying alternate list classes...\n");
  112.     list2 = New(List2);
  113.     add(list2, New(String, "one"),
  114.                New(String, "two"),
  115.                New(String, "three"), END);
  116.     print(list2);
  117.     
  118.     /*
  119.      * timing differences in making the 2 different list kinds
  120.      */
  121.     printf("\nmaking a 1000 element list\n");
  122.     time= TickCount();
  123.     list1 = New(List, END);
  124.     for (i = 0; i < 1000; i++)
  125.         push(list1, p1);
  126.     printf("done... sequencing it...\n");
  127.     for (i = 0, seq = sequence(list1); item = next(seq); )
  128.         i++;
  129.     printf("done, found %d items, %ld ticks\n", i, TickCount() - time);
  130.     
  131.     printf("making a 1000 element list2\n");
  132.     time= TickCount();
  133.     list2 = New(List2);
  134.     for (i = 0; i < 1000; i++)
  135.         push(list2, p1);
  136.     printf("done... sequencing it...\n");
  137.     for (i = 0, seq = sequence(list2); item = next(seq); )
  138.         i++;
  139.     printf("done, found %d items, %ld ticks\n", i, TickCount() - time);
  140.     
  141.     /*
  142.      * the class Class has a number of useful methods ...
  143.      */
  144.     printf("\nall Object subclasses...\n");
  145.     print(subs(Object));
  146.     
  147.     printf("all Collect subclasses...\n");
  148.     print(subs(Collect));
  149.     
  150.     printf("all List2 supers...\n");
  151.     print(supers(List2));
  152.     
  153.     /*
  154.      * play around with the very simple window class. Note that
  155.      * it uses List as a mixin to provide a simple contents list.
  156.      * I am also experimenting with keyword parameters, a la Lisp -
  157.      * see window.c see & key_arg() in oic.h for details
  158.      */
  159.     w = New(Window, BOUNDS, &bounds,
  160.                     TITLE, "\pJohn's",
  161.                     KIND, (long)rDocProc,
  162.                     END);
  163.     
  164.     add(w, box1, New(Box, 150.0, 150.0, 190.0, 190.0), END);
  165.     draw(w);
  166.     print(w);
  167.  
  168.     printf("all done\n");
  169. }
  170.  
  171. InitTestClasses()
  172. {
  173.     InitCoordClass();
  174.     InitBoxClass();
  175.     InitWindowClass();
  176. }    
  177.